package com.fosun.spr.plugin.shiro.api.control;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.fosun.spr.core.base.CoBaseControl;
import com.fosun.spr.core.utils.SessionUtils;
import com.fosun.spr.plugin.shiro.api.service.UucLoginService;
import com.fosun.spr.plugin.shiro.api.service.model.HasPrivilegeSpModel;
import com.fosun.spr.plugin.shiro.api.service.model.HasPrivilegeSrModel;
import com.fosun.spr.plugin.shiro.api.service.model.ListUserMenusSpModel;
import com.fosun.spr.plugin.shiro.api.service.model.ListUserMenusSrModel;
import com.fosun.spr.plugin.shiro.api.service.model.NeedLoginErrorSpModel;
import com.fosun.spr.plugin.shiro.api.service.model.NeedLoginErrorSrModel;
import com.fosun.spr.plugin.shiro.api.service.model.SubmitLoginSpModel;
import com.fosun.spr.plugin.shiro.api.service.model.SubmitLoginSrModel;
import com.fosun.spr.plugin.shiro.api.service.model.SubmitLogoutSpModel;
import com.fosun.spr.plugin.shiro.api.service.model.SubmitLogoutSrModel;

@RestController
public class UucLoginControl extends CoBaseControl {
	@Resource
	private UucLoginService uucLoginService;

	// /**
	// * http://127.0.0.1:8080//api/uucLogin/getUserByLoginNo
	// * http://127.0.0.1:8081/api/uucLogin/getUserByLoginNo
	// *
	// * @param request
	// * @param spModel
	// * @return
	// */
	// @RequestMapping(value = "/api/uucLogin/getUserByLoginNo",method =
	// RequestMethod.GET)
	// public GetUserByLoginNoSrModel getUserByLoginNo(HttpServletRequest request,
	// GetUserByLoginNoSpModel spModel) {
	// //SessionUtils.fillSpModel(request, spModel);
	// GetUserByLoginNoSrModel srModel = uucLoginService.getUserByLoginNo(spModel);
	// return srModel;
	// }
	/**
	 * http://127.0.0.1:8080//api/uucLogin/submitLogin
	 * http://127.0.0.1:8081/api/uucLogin/submitLogin {"":"","":""}
	 * 
	 * @param request
	 * @param spModel
	 * @return
	 */
	@RequestMapping(value = "/api/uucLogin/submitLogin", method = RequestMethod.POST)
	public SubmitLoginSrModel submitLogin(HttpServletRequest request, @RequestBody SubmitLoginSpModel spModel) {
		// SessionUtils.fillSpModel(request, spModel);
		SubmitLoginSrModel srModel = uucLoginService.submitLogin(spModel);
		return srModel;
	}
	
	/**
	 * http://127.0.0.1:8080//api/uucLogin/submitLogout
	 * http://127.0.0.1:8081/api/uucLogin/submitLogout
	 * 
	 * @param request
	 * @param spModel
	 * @return
	 */	
	@RequestMapping(value = "/api/uucLogin/submitLogout",method = RequestMethod.GET)
	public SubmitLogoutSrModel submitLogout(HttpServletRequest request, SubmitLogoutSpModel spModel) {
		//SessionUtils.fillSpModel(request, spModel);
		SubmitLogoutSrModel srModel = uucLoginService.submitLogout(spModel);
		return srModel;
	}

	/**
	 * http://127.0.0.1:8080//api/uucLogin/needLoginError
	 * http://127.0.0.1:8081/api/uucLogin/needLoginError
	 * 
	 * @param request
	 * @param spModel
	 * @return
	 */
	@RequestMapping(value = "/api/uucLogin/needLoginError", method = RequestMethod.GET)
	public NeedLoginErrorSrModel needLoginError(HttpServletRequest request, NeedLoginErrorSpModel spModel) {
		// SessionUtils.fillSpModel(request, spModel);
		NeedLoginErrorSrModel srModel = uucLoginService.needLoginError(spModel);
		return srModel;
	}

	/**
	 * http://127.0.0.1:8080//api/uucLogin/listUserMenus
	 * http://127.0.0.1:8081/api/uucLogin/listUserMenus
	 * 
	 * @param request
	 * @param spModel
	 * @return
	 */
	@RequestMapping(value = "/api/uucLogin/listUserMenus", method = RequestMethod.GET)
	public ListUserMenusSrModel listUserMenus(HttpServletRequest request, ListUserMenusSpModel spModel) {	
		SessionUtils.fillSpModel(request, spModel);
		ListUserMenusSrModel srModel = uucLoginService.listUserMenus(spModel);
		return srModel;
	}
	
	/**
	 * http://127.0.0.1:8080//api/uucLogin/hasPrivilege
	 * http://127.0.0.1:8081/api/uucLogin/hasPrivilege
	 * {"":"","":""}
	 * @param request
	 * @param spModel
	 * @return
	 */	
	@RequestMapping(value = "/api/uucLogin/hasPrivilege",method = RequestMethod.POST)
	public HasPrivilegeSrModel hasPrivilege(HttpServletRequest request,@RequestBody HasPrivilegeSpModel spModel) {
		//SessionUtils.fillSpModel(request, spModel);
		HasPrivilegeSrModel srModel = uucLoginService.hasPrivilege(spModel);
		return srModel;
	}

}
